let app=getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    items:{
      type:Object,
      value:{},
      observer(newVal, oldVal, changedPath) {

      }
    },
    index:{
      type:Number ,
      value:null,
      observer(newVal, oldVal, changedPath) {

      }
    },
    imgHeight:{
      type:Number ,
      value:400,
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    play:false,
    theme:app.theme,
    number:0,
  },
  // 当切换模式改变
  attached(){
    this.setData({
      theme:app.theme
    })
  },
  ready: function() { 
  },
  /**
   * 组件的方法列表
   */
  methods: {
    // 拉起规格
    addOneCart(e){
      let that=this;
      let item=e.currentTarget.dataset.item;
      that.triggerEvent('addCart',{goods:item,index:that.data.index});
    },

    // 播放视频
    getPlayVideo(){
      if(app.videoContext.length>0){
        app.videoContext.forEach((item)=>{
          console.info(item);
          item.pause();
        })
      }
      app.videoId=this.data.items.id;
      app.videoContext[this.data.items.id]=wx.createVideoContext('myVideo'+this.data.items.id,this);
      this.setData({
        play:true
      },()=>{
        app.videoContext[this.data.items.id].play();
      })
      console.info(app.videoId,app.videoContext);
    },
    close(){
      app.videoId='';
      this.setData({
        play:false
      })
    },
    play(e){
      if(app.videoContext.length>0){
        app.videoContext.forEach((item,key)=>{
          if(key==this.data.items.id){
            app.videoId=this.data.items.id;
            item.play();
          }else{
            item.pause();
          }
        })
      }
    },
    // 跳转到商品详情
    goDetail(e){
      let goodsid=e.currentTarget.dataset.goodid;
      wx.navigateTo({
        url: '/pages/detail/detail?goodsid='+goodsid
      })
    },

  }
})
